var thisObject,allxml;
var object;
var vehicleSingle;
var curTabIndex = 0;
var preTabIndex = 0;
var allInfoPage;
var vehicleInfoPage;
var contactInfoPage;
var commentInfoPage;
var locationInfoPage;
var priceInfoPage;

var DetailPageMediator = Objs("view.DetailPageMediator",
	Mediator,
{

	initialize: function( name, viewComponent )
	{   
		DetailPageMediator.$super.initialize.call( this, name, viewComponent );
    	        this.vProxy = this.facade.retrieveProxy( ProxyNames.VEHICLE_PROXY );
    	        this.assetProxy = this.facade.retrieveProxy( ProxyNames.INITIAL_PROXY );
				this.vProxy.setMode( AppConstants.APP_ADD);
		//this.loginProxy = this.facade.retrieveProxy( ProxyNames.LOGIN_PROXY );
		this.registerListeners();
                vehicleSingle = new VehicleVO();
		thisObject = this;
           
               
              
                
	},
	set:function()
	{
	
		if(getUrlVars()["id"])
		{  
				   $("#vehicle-info-title").show();
				   $("#allinfo_correspondence").show();
				   $('li').removeClass('active').addClass('inactive');
				   $('#ainfo-li').removeClass('inactive').addClass('active');
				 
				   this.vProxy.getDetail(getUrlVars()["id"]);
				 
		 }
		 else
		 {
			   this.showAddNewWindow();
			   
		 }    
	},
	registerListeners: function()
	{   
		var detailPage = this.get();	
		detailPage.addEventListener( DetailPage.LOAD_ALL_INFO, this.loadAllInfo, this );
		detailPage.addEventListener( DetailPage.LOAD_VEHICLE_INFO, this.loadVehicleInfo, this );
		detailPage.addEventListener( DetailPage.LOAD_CUSTOMER_INFO, this.loadContactInfo, this );
		detailPage.addEventListener( DetailPage.LOAD_VLOCATION_INFO, this.loadVehicleLocationInfo, this );
		detailPage.addEventListener( DetailPage.LOAD_COMENT_INFO, this.loadCommentInfo, this );
		detailPage.addEventListener( DetailPage.LOAD_PRICEINFO, this.loadPriceInfo, this );
		detailPage.addEventListener( DetailPage.SAVE_INFO, this.saveInfoHandler, this );
		detailPage.addEventListener( DetailPage.CANCEL_INFO, this.cancelInfoHandler, this );
		detailPage.addEventListener( DetailPage.SET_TOW_STATUS, this.setTowStatusHandler, this );
		detailPage.addEventListener( DetailPage.WATCHLIST_START, this.watchstart, this );
		detailPage.addEventListener( DetailPage.SHARE_START, this.sharestart, this );
		//detailPage.addEventListener(DetailPage.MAKE_CHANGE , this.makechange, this );
	},
	get: function()
	{
		return this.viewComponent;
		
	},
    watchstart:function()
	{
		if ($(jQuery("#checkbox-1")).attr('checked')) {
			$('#hidecont').show('slow');
		}
		else
		{
			$('#hidecont').hide('slow');
		}
		
		if(this.facade.hasMediator(MediatorNames.WATCH_MEDIATOR)==false)
		{
		var watchPage = new WatchPage();
             
		var watchPageMediator = new WatchPageMediator( MediatorNames.WATCH_MEDIATOR, watchPage);
                
		this.facade.registerMediator( watchPageMediator );
		}
		this.vProxy.getreminderbyid();
	}, 
	sharestart:function()
	{
		$(jQuery("#useanother")).attr('checked',false);
		$(jQuery("#cardetcheck")).attr('checked',false);
		$(jQuery("#sellerdetcheck")).attr('checked',false);
		$(jQuery("#privatnotcheck")).attr('checked',false);
		$(jQuery("#towdetcheck")).attr('checked',false);
		$(jQuery("#mapcheck")).attr('checked',false);
		$("#selectdiv").show();
		$("#anoemaildiv").hide();
		$("#anoemail").val('');
		$("#anynote").val('');
		if(this.facade.hasMediator(MediatorNames.SHARE_MEDIATOR)==false)
		{
		var sharePage = new SharePage();
             
		var sharePageMediator = new SharePageMediator( MediatorNames.SHARE_MEDIATOR, sharePage);
                
		this.facade.registerMediator( sharePageMediator );
		}
		this.vProxy.getPartnerlist();
		
	},
	setTowStatusHandler: function()
	{

	   this.vProxy.setTowStatus(vehicleSingle.vehicle_id);
	},
       
	saveInfoHandler: function()
	{ 
		var cMode = this.vProxy.getMode();
		
		this.bindTabValues();
		
		if( cMode == AppConstants.APP_MODIFY )
		{
			vehicleSingle.isNormal = 1;
			
			this.vProxy.updateVehicle(vehicleSingle);
		}
		else if(cMode == AppConstants.APP_ADD)
		{
		  if($("#make").val()!=0 && $("#model").val()!=0  )
			this.vProxy.addNewVehicle(vehicleSingle);
			else
			bootbox.alert("Missing Fields");
		}
	},
	cancelInfoHandler: function()
	{   
		
		$("#vehicle-content-info").hide();
        $("#vehicle-list-page").show();
         $('li').removeClass('active').addClass('inactive');
        $('#new-vehicle-component').removeClass('inactive').addClass('active');       
		this.vProxy.unlockOpenVehicle();
          window.location='vehicle_list.php?tab=1';
	},
	unregisterListeners: function()
	{
		
	},
	listNotificationInterests: function()
	{
		return [
				NotificationNames.ADDNEW,
				NotificationNames.INFO_READY,
				NotificationNames.SAVE_SUCCESS,
				NotificationNames.ADD_MESSAGE_SUCCESS,
				NotificationNames.LOAD_SUCCESS_2,
					NotificationNames.ADD_NEW_SUCCESS
		];
	},
    handleNotification: function( note )
	{ 
		
		switch ( note.getName() )
		{ 
			case NotificationNames.ADDNEW:
                            
				this.showAddNewWindow();
                                
				break;
			case NotificationNames.ADD_NEW_SUCCESS:
                // bootbox.alert("Vehicle Created");
				 
            bootbox.alert("Vehicle Created", function() {
               thisObject.cancelInfoHandler();
            
			});
				
                                
				break;	
			case NotificationNames.INFO_READY:
			   
			 	this.showInfoPage();
			 	
			 	 
			  	break;
			case NotificationNames.SAVE_SUCCESS:
			 	this.checkSaveData(note.getBody());
			  	break;
			case NotificationNames.ADD_MESSAGE_SUCCESS:
				this.updateCorrespondence(note.getBody());
				break;
			case NotificationNames.ADD_PNOTE_SUCCESS:	
				this.updatePrivateNote(note.getBody());
				break;
				case NotificationNames.LOAD_SUCCESS_2:	
				this.set();
				break;
		}
	},
	updatePrivateNote: function(privateList)
	{
		document.getElementById("list_private").innerHTML = '';
		for(var i=0;i<privateList.pnote.length;i++)
		{ 
			document.getElementById("list_private").innerHTML+="<div class='commentBox'> <div id=messagehead><strong>On " +privateList.pnote[i].dateTime+ " " +privateList.pnote[i].messageOwener+ " Wrote</strong></div><hr align='center' width='100%' style='color:#CCC'/><div id=messagedetail>" +privateList.message[i].pnote+ "</div></div>"; 
		}
	},
	updateCorrespondence: function(messageList)
	{
		document.getElementById("list_correspond").innerHTML = '';
		for(var i=0;i<messageList.message.length;i++)
		{ 
			document.getElementById("list_correspond").innerHTML+="<div class='commentBox'> <div id=messagehead><strong>On " +messageList.message[i].dateTime+ " " +messageList.message[i].messageOwener+ " Wrote</strong></div><hr align='center' width='100%' style='color:#CCC'/><div id=messagedetail>" +messageList.message[i].message+ "</div></div>"; 
		}
	},
	checkSaveData: function(getVal)
	{ 
		if(getVal.data!="true")
		{ 
			var r=confirm("The vehicle is already locked by "+getVal.data+" Do u want to save?");
			if (r==true)
			{
				vehicleSingle.isNormal = 0;
				this.vProxy.updateVehicle(vehicleSingle);
			}
			else
			{
				this.cancelInfoHandler();
			}	
		}
		else
		{
		this.cancelInfoHandler();
		}		
	},
	bindOtherTabValues: function()
	{
		if(curTabIndex != preTabIndex){
			switch ( preTabIndex ){
				case 0:
					this.setNewAllInfoValue();
					break;
				case 1:
					this.setNewVehicleInfoValue();
					break;
				case 2:
					this.setNewContactInfoValue();
					break;
				case 3:
					this.setNewVLocationInfoValue();
					break;
			}
		}
	},
	bindTabValues: function()
	{
		switch ( curTabIndex ){
				case 0:
					this.setNewAllInfoValue();
					break;
				case 1:
					this.setNewVehicleInfoValue();
					break;
				case 2:
					this.setNewContactInfoValue();
					break;
				case 3:
					this.setNewVLocationInfoValue();
					break;
			}
	},
	regAllInfo:function()
	{     
	
		var allInfoPage = new AllInfoPage();
             
		var allInfoMediator = new AllInfoMediator( MediatorNames.ALL_INFO_MEDIATOR, allInfoPage);
                
		this.facade.registerMediator( allInfoMediator );
        //this.sendNotification( NotificationNames.SHOW_DIR_MAP, vehicleSingle.v_street_address+", "+vehicleSingle.v_city+", "+vehicleSingle.v_state);     
	},
	loadAllInfo:function()
	{
		
		
		preTabIndex = curTabIndex;
		curTabIndex = 0;
		this.bindOtherTabValues();
               
		if($("#all-info-content").contents().length == 0)
		{     
			var url;
            if(global_user.admin_type=="Tower Administrator")
                url = "info/all-info-view.php";
             else
                 {
                     if(global_user.vehicle_role==8)
                          url = "info/all-info-view.php";
                     else 
                            url = "info/all-info.php";
                 }              
			$.ajax({ url: url, success: function(html) {
				$("#all-info-content").append(html);
				thisObject.regAllInfo();
					if(global_user.admin_type=="Tower Administrator")
						thisObject.setViewInfoValues();
					else
                                            {
                                            if( global_user.vehicle_role==8)
                                                    thisObject.setViewInfoValues();
                                            else
						thisObject.sendNotification( NotificationNames.SETALLVALUE, 'li' );
                                            }
                                
				}
			});
                       
		}
		else
		{ 
			if(global_user.admin_type=="Tower Administrator")
				thisObject.setViewInfoValues();
			else
                        {
                              if( global_user.vehicle_role==8)
                                  thisObject.setViewInfoValues();
                              else
                                	thisObject.sendNotification( NotificationNames.SETALLVALUE, 'li' );
                                 }
		}
		
		$('#all-info-content').show();	
              
		$('#vehicle-info-content').hide();
		$('#contact-info-content').hide();
		$('#location-info-content').hide();
		$('#comment-info-content').hide();
		$('#tow-info-content').hide();
		$('#price-info-content').hide();
	  
		//$( "#remove_by" ).datepicker();
		
	},
	setNewAllInfoValue: function ()
	{     
		
        vehicleSingle.year = document.getElementById('year').value;
		vehicleSingle.make = document.getElementById('make').value;
		vehicleSingle.model = document.getElementById('model').value;
		vehicleSingle.mileage = document.getElementById('mileage').value ;
		vehicleSingle.great = document.getElementById('great').value;
		vehicleSingle.wrong = document.getElementById('wrong').value;
		vehicleSingle.paper_work = document.getElementById('paper_work').value ;
		vehicleSingle.title_name = document.getElementById('title').value ;
		vehicleSingle.title_note = document.getElementById('title_note').value ;
		vehicleSingle.ad_source = document.getElementById('ad_source').value ;
		vehicleSingle.vin = document.getElementById('vin').value;
		vehicleSingle.drivetrain_type = document.getElementById('drive_train_type').value;
		vehicleSingle.engine = document.getElementById('engine').value ;
		vehicleSingle.transmission = document.getElementById('transmission').value;
		vehicleSingle.first_name = document.getElementById('first_name').value;
		vehicleSingle.business_name = document.getElementById('business_name').value;	
		vehicleSingle.contact_name = document.getElementById('contact_name').value;
		vehicleSingle.street_address = document.getElementById('street_address').value;
		vehicleSingle.city = document.getElementById('city').value;
		vehicleSingle.state = document.getElementById('state').value;
		vehicleSingle.zip = document.getElementById('zip').value;
		vehicleSingle.phone = document.getElementById('phone').value;
		vehicleSingle.cell_phone = document.getElementById('cell_phone').value;
		vehicleSingle.email = document.getElementById('e_mail').value;
		vehicleSingle.contact_me = document.getElementById('contact_method').value;
		vehicleSingle.contact_note = document.getElementById('seller_note').value;		
		vehicleSingle.v_street_address = document.getElementById('v_address').value;
		vehicleSingle.v_city = document.getElementById('v_city').value;
		vehicleSingle.v_state = document.getElementById('v_state').value;	
		vehicleSingle.v_zip = document.getElementById('v_zip').value;
		vehicleSingle.delivery = document.getElementById('delivery').value;
		vehicleSingle.remove_by = document.getElementById('remove_by').value;         
		vehicleSingle.delivery_note = document.getElementById('transport_note').value;
		vehicleSingle.i_want_to = document.getElementById('i_want_to').value;
		vehicleSingle.delivery_option = document.getElementById('delivery_option').value;
		vehicleSingle.asking_price = document.getElementById('asking_price').value;
		vehicleSingle.bid_price = document.getElementById('bid_price').value;
		vehicleSingle.accepted_price = document.getElementById('accepted_price').value;
		 
	},
	setViewInfoValues: function()
	{

		$('li').removeClass('active').addClass('inactive');
		$('#all-view-details').removeClass('inactive').addClass('active'); 
		if(vehicleSingle.images.length>0)
		{   
				$('#view-title-image').attr("src",'../'+vehicleSingle.images[0].cropUrl);
				document.getElementById("galleryhead").innerHTML="Vehicle Images";
			for(i=0;i<vehicleSingle.images.length;i++)
			{ 
			
						document.getElementById("imageul").innerHTML+="  <li ><a  href=../"+vehicleSingle.images[i].cropUrl+ "><img class=thumbnail style=float:left;margin:5px; src=../"+vehicleSingle.images[i].thumpUrl+" width=72 height=72 alt=''></a></li>";			
						 $('#gallery a').lightBox(); 
			}
		}
			 
			 
		document.getElementById('vehicle-idmakemodel').innerHTML = "#"+vehicleSingle.vehicle_id + '-' + vehicleSingle.make_name + '  ' + vehicleSingle.model_name;
		document.getElementById('vehicle-yearmakemodel').innerHTML = vehicleSingle.year+ ' ' + vehicleSingle.make_name + '  ' + vehicleSingle.model_name;
	
		document.getElementById('vehicle-caller-name').innerHTML =  vehicleSingle.first_name;
	 //   document.getElementById('btn-status').innerHTML =  vehicleSingle.status;
	   // document.getElementById('vehicle-contact-method').innerHTML =  vehicleSingle.contact_me;
		document.getElementById('vehicle-citystate').innerHTML =  vehicleSingle.v_city+ ' / ' +vehicleSingle.v_state_name;
	   
		document.getElementById('vehicle-phone').innerHTML =  vehicleSingle.phone;
		document.getElementById('vehicle-remove_by').innerHTML =  vehicleSingle.remove_by;
	  
		document.getElementById('btn_towstatus').innerHTML =  vehicleSingle.tow_status_name;   
		document.getElementById('year').innerHTML = vehicleSingle.year;
		document.getElementById('make').innerHTML = vehicleSingle.make_name;
		document.getElementById('model').innerHTML = vehicleSingle.model_name;
		document.getElementById('mileage').innerHTML = vehicleSingle.mileage;
		document.getElementById('great').innerHTML = vehicleSingle.great;
		document.getElementById('wrong').innerHTML = vehicleSingle.wrong;
		//document.getElementById('paper_work').innerHTML = vehicleSingle.paper_work;
		//document.getElementById('title').innerHTML = vehicleSingle.title_name;
		//document.getElementById('title_note').innerHTML = vehicleSingle.title_note;
		//document.getElementById('ad_source').innerHTML = vehicleSingle.ad_source;
		document.getElementById('vin').innerHTML = vehicleSingle.vin;
		document.getElementById('drive_train_type').innerHTML = vehicleSingle.drivetrain_type;
		document.getElementById('engine').innerHTML = vehicleSingle.engine;
		document.getElementById('transmission').innerHTML = vehicleSingle.transmission;
		document.getElementById('first_name').innerHTML = vehicleSingle.first_name;
		document.getElementById('business_name').innerHTML = vehicleSingle.business_name;
			  
		document.getElementById('contact_name').innerHTML = vehicleSingle.contact_name;
		document.getElementById('street_address').innerHTML = vehicleSingle.street_address;
		document.getElementById('city').innerHTML = vehicleSingle.city;
		document.getElementById('state').innerHTML = vehicleSingle.state_name;
		document.getElementById('zip').innerHTML = vehicleSingle.zip;
		document.getElementById('phone').innerHTML = vehicleSingle.phone;
		document.getElementById('cell_phone').innerHTML = vehicleSingle.cell_phone;
		document.getElementById('e_mail').innerHTML = vehicleSingle.email;
		document.getElementById('contact_method').innerHTML = vehicleSingle.contact_me;
		document.getElementById('seller_note').innerHTML = vehicleSingle.contact_note;
		
		document.getElementById('v_address').innerHTML = vehicleSingle.v_street_address;
		document.getElementById('v_city').innerHTML = vehicleSingle.v_city;
		document.getElementById('v_state').innerHTML = vehicleSingle.v_state_name;
		document.getElementById('v_zip').innerHTML = vehicleSingle.v_zip;
		document.getElementById('delivery').innerHTML = vehicleSingle.delivery;
		document.getElementById('remove_by').innerHTML = vehicleSingle.remove_by;
		document.getElementById('transport_note').innerHTML = vehicleSingle.delivery_note;
		var location = new Object();
		if(vehicleSingle.v_street_address==''&&vehicleSingle.v_city==''&&vehicleSingle.v_state=='')
			location.vlocation = vehicleSingle.street_address+", "+vehicleSingle.city+", "+vehicleSingle.state_name;
		else
			 location.vlocation = vehicleSingle.v_street_address+", "+vehicleSingle.v_city+", "+vehicleSingle.v_state_name;
		 
		location.tlocation= vehicleSingle.tower_street+", "+vehicleSingle.tower_city+", "+vehicleSingle.tower_state;    
	
		 this.sendNotification( NotificationNames.SHOW_DIR_MAP, location);

	},
 
	regVehicleInfo:function()
	{
		vehicleInfoPage = new VehicleInfoPage();
		var vehicleInfoMediator = new VehicleInfoMediator( MediatorNames.VEHICLE_INFO_MEDIATOR, vehicleInfoPage);
		this.facade.registerMediator( vehicleInfoMediator );
	},
	loadVehicleInfo:function()
	{ 	
		preTabIndex = curTabIndex;
		curTabIndex = 1;
		this.bindOtherTabValues();
		if($("#vehicle-info-content").contents().length == 0)
		{		
			$.ajax({ url: 'info/vehicle-info.php', success: function(html) {
				
				$("#vehicle-info-content").append(html);
				thisObject.regVehicleInfo();
				var minyear=1900;
				var date = new Date();
				var maxyear = date.getFullYear();
				var yearCombo = '';
				
				for (var i=minyear;i<=maxyear;i++)
				{
					if(i==1990)
					{
						yearCombo += "<option selected='true'>"+i+"</option>";
					}
					yearCombo += '<option>'+i+'</option>';
				}
				
				preTabIndex = curTabIndex;
				curTabIndex = 1;
				$("#v_year").append(yearCombo);
				$("#v_year").trigger("change");
				$("#v_make").append(initialdet.makexml);
				$("#v_paper_work").append(initialdet.paperxml);
				$("#v_ad_source").append(initialdet.adsourcexml);
				$("#v_drivetrain_type").append(initialdet.drivetrain);
				$("#v_engine").append(initialdet.enginexml);
				$("#v_transmission").append(initialdet.transxml);
				thisObject.sendNotification( NotificationNames.SETVIEWVALUE, 'li' );	
				}
				
			});	
		}
		else
		{
			thisObject.sendNotification( NotificationNames.SETVIEWVALUE, 'li' );	
		}
		
		$('#all-info-content').hide();
		$('#vehicle-info-content').show();
		$('#contact-info-content').hide();
		$('#location-info-content').hide();
		$('#comment-info-content').hide();
		$('#tow-info-content').hide();
		$('#price-info-content').hide();
	},
	setNewVehicleInfoValue: function ()
	{
		vehicleSingle.year = document.getElementById('v_year').value;
		vehicleSingle.make = document.getElementById('v_make').value; 
		vehicleSingle.model = document.getElementById('v_model').value;
		vehicleSingle.mileage = document.getElementById('v_mileage').value ;
		vehicleSingle.great = document.getElementById('v_great').value;
		vehicleSingle.wrong = document.getElementById('v_wrong').value;
		vehicleSingle.paper_work = document.getElementById('v_paper_work').value ;
		vehicleSingle.title_name = document.getElementById('v_title_name').value ;
		vehicleSingle.title_note = document.getElementById('v_title_note').value ;
		vehicleSingle.ad_source = document.getElementById('v_ad_source').value ;
		vehicleSingle.vin = document.getElementById('v_vin').value;
		vehicleSingle.drivetrain_type = document.getElementById('v_drivetrain_type').value;
		vehicleSingle.engine = document.getElementById('v_engine').value ;
		vehicleSingle.transmission = document.getElementById('v_transmission').value;

	},
	regContactInfo:function()
	{
		var contactInfoPage = new ContactInfoPage();
		var contactInfoMediator = new ContactInfoMediator( MediatorNames.CONTACT_INFO_MEDIATOR, contactInfoPage);
		this.facade.registerMediator( contactInfoMediator );
	},
	loadContactInfo:function()
	{
		preTabIndex = curTabIndex;
		curTabIndex = 2;
		this.bindOtherTabValues();
		if($("#contact-info-content").contents().length == 0)
		{
			$.ajax({ url: 'info/contact-info.php', success: function(html) {
				thisObject.regContactInfo();
				$("#contact-info-content").append(html);				
				$("#c_state").append(initialdet.statexml);
				$("#c_contact_me").append(initialdet.contactxml);
				$("#c_delivery").append(initialdet.transportationxml);
					thisObject.sendNotification( NotificationNames.SETCONVALUE, 'li' );	
				}
			});	
		}
		else
		{
				thisObject.sendNotification( NotificationNames.SETCONVALUE, 'suc' );
		}
		$('#contact-info-content').show();
		$('#all-info-content').hide();
		$('#vehicle-info-content').hide();
		$('#location-info-content').hide();
		$('#comment-info-content').hide();
		$('#tow-info-content').hide();
		$('#price-info-content').hide();
	},
	setNewContactInfoValue: function ()
	{
		vehicleSingle.first_name = document.getElementById('c_first_name').value;
		vehicleSingle.business_name = document.getElementById('c_business_name').value;
	
		vehicleSingle.contact_name = document.getElementById('c_contact_name').value;
		vehicleSingle.street_address = document.getElementById('c_street_address').value;
		vehicleSingle.city = document.getElementById('c_city').value;
		vehicleSingle.state = document.getElementById('c_state').value;
		vehicleSingle.zip = document.getElementById('c_zip').value;
		vehicleSingle.phone = document.getElementById('c_phone').value;
		vehicleSingle.cell_phone = document.getElementById('c_cell_phone').value;
		vehicleSingle.email = document.getElementById('c_email').value;
		vehicleSingle.contact_me = document.getElementById('c_contact_me').value;
		vehicleSingle.contact_note = document.getElementById('c_seller_note').value;
		vehicleSingle.delivery = document.getElementById('c_delivery').value;
		vehicleSingle.delivery_note= document.getElementById('c_transport_note').value;
	},
	
	regLocationInfo:function()
	{
		var locationInfoPage = new LocationInfoPage();
		var locationInfoMediator = new LocationInfoMediator( MediatorNames.LOCATION_INFO_MEDIATOR, locationInfoPage);
		this.facade.registerMediator( locationInfoMediator );
		
	},
	loadVehicleLocationInfo:function()
	{
		preTabIndex = curTabIndex;
		curTabIndex = 3;
		this.bindOtherTabValues();
		
		if($("#location-info-content").contents().length == 0)
		{
			
			$.ajax({ url: 'info/vehicle-location-info.php', success: function(html) {
				$("#location-info-content").append(html);
				thisObject.regLocationInfo();
				$("#vl_v_state").append(initialdet.statexml);
				$("#vl_delivery_option").append(initialdet.optionDelivery);
				$("#vl_i_want_to").append(initialdet.want);
				thisObject.sendNotification( NotificationNames.SETVLOCVALUE, 'suc' );
				}
			});	
		}
		else
		{
			thisObject.sendNotification( NotificationNames.SETVLOCVALUE, 'suc' );
		}
		
		$('#location-info-content').show();
		$('#contact-info-content').hide();
		$('#all-info-content').hide();
		$('#vehicle-info-content').hide();
		$('#comment-info-content').hide();
		$('#tow-info-content').hide();
		$('#price-info-content').hide();
	},
	setNewVLocationInfoValue: function ()
	{
		vehicleSingle.v_street_address = document.getElementById('vl_v_address').value;
		vehicleSingle.v_city = document.getElementById('vl_v_city').value;
		vehicleSingle.v_state = document.getElementById('vl_v_state').value;
		vehicleSingle.v_zip = document.getElementById('vl_v_zip').value;
		vehicleSingle.i_want_to = document.getElementById('vl_i_want_to').value;
		vehicleSingle.delivery_option = document.getElementById('vl_delivery_option').value;
	},
	
	regCommentInfo:function()
	{
		commentInfoPage = new CommentInfoPage();
		var commentInfoMediator = new CommentInfoMediator( MediatorNames.COMMENT_INFO_MEDIATOR, commentInfoPage);
		this.facade.registerMediator( commentInfoMediator );
	},
	loadCommentInfo:function()
	{
		preTabIndex = curTabIndex;
		curTabIndex = 4;
		this.bindOtherTabValues();
		if($("#comment-info-content").contents().length == 0)
		{
			
			$.ajax({ url: 'info/comment-info.php', success: function(html) {
				
				$("#comment-info-content").append(html);
				thisObject.regCommentInfo();
				thisObject.sendNotification( NotificationNames.SETCOMVALUE, 'suc' );
				}
			});	
		}
		else
		{
			thisObject.sendNotification( NotificationNames.SETCOMVALUE, 'suc' );
		}
		
		$('#comment-info-content').show();
		$('#location-info-content').hide();
		$('#contact-info-content').hide();
		$('#all-info-content').hide();
		$('#vehicle-info-content').hide();
		$('#tow-info-content').hide();
		$('#price-info-content').hide();
		
	},

	loadPriceInfo:function()
	{
		preTabIndex = curTabIndex;
		curTabIndex = 5;
		this.bindOtherTabValues();
		if($("#price-info-content").contents().length == 0)
		{
			$.ajax({ url: 'info/price-info.php', success: function(html) {
				
				$("#price-info-content").append(html);
				thisObject.setPriceInfoValue();
				}
			});	
		}
		else
		{
			thisObject.setPriceInfoValue();
		}
		
		$('#price-info-content').show();
		$('#tow-info-content').hide();
		$('#comment-info-content').hide();
		$('#location-info-content').hide();
		$('#contact-info-content').hide();
		$('#all-info-content').hide();
		$('#vehicle-info-content').hide();
	},
	setNewPriceInfoValue: function ()
	{
		vehicleSingle.asking_price = document.getElementById('p_asking_price').value;
		vehicleSingle.bid_price = document.getElementById('p_bid_price').value;
		vehicleSingle.accepted_price = document.getElementById('p_accepted_price').value;
	},
	setPriceInfoValue: function ()
	{
		document.getElementById('p_asking_price').value = vehicleSingle.asking_price;
		document.getElementById('p_bid_price').value = vehicleSingle.bid_price;
		document.getElementById('p_accepted_price').value = vehicleSingle.accepted_price;
	},
	showAddNewWindow:function()
	{  
		
                this.bindOtherTabValues();
               
		//thisObject.hideNonInfo();
		//doResize();
        
                   
			$.ajax({ url: "info/all-info.php", success: function(html) {
			
				$("#all-info-content").append(html);
				 thisObject.regAllInfo();

			$("#allinfo_correspondence").hide();
				thisObject.setDataProviders();
                              
				}
			});	
		
                
                
	},
	showInfoPage: function()
	{
          
             	thisObject.hideNonInfo();
               
		preTabIndex = 0;
		curTabIndex = 0;
                
		if($("#all-info-content").contents().length == 0)
		{   
                     var url;
                    if(global_user.admin_type=="Tower Administrator")
                        url = "info/all-info-view.php";
                    else
                        {
                            
                            if(global_user.vehicle_role==8)
                                 url = "info/all-info-view.php";
                            else    
                                url = "info/all-info.php";
                        }
			$.ajax({ url: url, success: function(html) {
                               
				$("#all-info-content").append(html);
                                
                                        thisObject.regAllInfo();

                                        thisObject.setDataProviders();

                                        thisObject.setInfoValues();
                                         $(".container").show();
                                          $("#progressviewpage").hide();
                                     
				}
			});	
		}
		else
		{ 
			thisObject.setInfoValues(); 
                         
		}
		
	},
	
	setInfoValues: function()
	{   
		vehicleSingle = null;
		vehicleSingle = this.vProxy.getVehicleSingle();
		thisObject.loadAllInfo();	
	},
	
	setDataProviders: function()
	{ 
		var minyear=1900;
		var date = new Date();
		var maxyear = date.getFullYear();
		var yearCombo = '';
		
		for (var i=minyear;i<=maxyear;i++)
		{
			if(i==1990)
			{
				yearCombo += "<option selected='true'>"+i+"</option>";
			}
			yearCombo += '<option>'+i+'</option>';
		}
		
		$("#year").append(yearCombo);
		$("#year").trigger("change");
		
		$("#make").append(initialdet.makexml);
	
		thisObject.assetProxy.setmodel();
		$('select#make').change(function() {
				thisObject.assetProxy.setmodel();
		});	
		$("#paper_work").append(initialdet.paperxml);
		$("#ad_source").append(initialdet.adsourcexml);
		$("#drive_train_type").append(initialdet.drivetrain);
		$("#engine").append(initialdet.enginexml);
		$("#transmission").append(initialdet.transxml);
		
		$("#state").append(initialdet.statexml);
		$("#contact_method").append(initialdet.contactxml);
		$("#v_state").append(initialdet.statexml);
		$("#delivery").append(initialdet.transportationxml);
		$("#i_want_to").append(initialdet.want);
		$("#delivery_option").append(initialdet.optionDelivery);
	},
	
	hideNonInfo: function()
	{       
        $("#vehicle-list-page").hide();
		$("#vehicle-content-info").show();
		$('#all-info-content').show();	
		$('#vehicle-info-content').hide();
		$('#contact-info-content').hide();
		$('#location-info-content').hide();
		$('#comment-info-content').hide();
		$('#tow-info-content').hide();
		$('#price-info-content').hide();
		$('#vehicle-tool-bottom').hide();
		$('#pagePanel').hide();
		$('#vehicle-list-header').hide();
		$('#info_mod_panel').show();
	}
	
	
});

